package org.hhchat.leetcode.bit;

import java.util.ArrayList;
import java.util.List;

/**
 * Created this one by HMH on 2017/10/1.
 */
public class code401_easy {
    static class  Solution{
        public List<String> readBinaryWatch(int num) {
            int[] clock = new int[10];
            visit(clock,0,0,num);
            return result;
        }

        public void visit(int[] clock,int count,int index,int target){
            if(count==target){
                String clockStr = setCloc(clock);
                if(clockStr!=null)
                    result.add(clockStr);
                return;
            }
            for(int i = index;i<clock.length;i++){
                clock[i] = 1;
                visit(clock,count+1,i+1,target);
                clock[i] = 0;
            }
        }

        List<String> result = new ArrayList<>();

        public String setCloc(int []clock){
            int hour = clock[0]*8+clock[1]*4+clock[2]*2+clock[3]*1;
            if (hour >= 12) {
                return null;
            }
            int minute = clock[4]*32+clock[5]*16+clock[6]*8+clock[7]*4+clock[8]*2+clock[9]*1;
            if (minute > 59) {
                return null;
            }
            return String.valueOf(hour)+":"+String.format("%02d",minute);
        }
    }

    public static void main(String[] args){
        Solution solution = new Solution();
        System.out.println(solution.readBinaryWatch(6));
    }
}
